<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateTableGuard extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function up()
    {
        if (!($this->hasTable('guard'))) {
            $table = $this->table("guard",['id' => false, 'primary_key' => ['id'],"collation" => "utf8mb4_unicode_ci"]);
            $table->addColumn("id","integer",["identity"=>true,"comment" => "主码"])
                ->addColumn("room_id","integer",["comment" => "房间ID"])
                ->addColumn("user_id","integer",["comment" => "发送人ID"])
                ->addColumn("gift_id","integer",["comment" => "礼物在B站的ID"])
                ->addColumn("gift_name","string",["comment" => "礼物在B站的名称"])
                ->addColumn("start_time","integer",["comment" => "唯一标识"])
                ->addColumn("price","string",["comment" => "礼物在B站的价格"])
                ->addColumn("file_date","date",["comment" => "本条记录来自日期"])
                ->addColumn("create_time","datetime",["comment" => "本条记录创建时间"])
                ->addColumn("update_time","datetime",["comment" => "本条记录更新时间"])
                ->create();
        }
    }

    public function down()
    {
        if ($this->hasTable('guard')) {
            $this->dropTable('guard');
        }
    }
}
